package com.ujiuye.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/jsonDemo")
public class ServletDemo02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        //返回一个符合json格式的字符串
        //String str = "{\"id\":10,\"name\":\"张三\"}";
        // String str ="[\"hello\",20,\"你好\"]";
        String str="[{\"id\":10,\"name\":\"张三\"},{\"id\":101,\"name\":\"张三101\"}]";
        resp.getWriter().println(str);
    }
}
